package com.gogowan.agroenterprise.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;

public class NetWorkManger {
    public static boolean hasNet(Context context){
        boolean isNet=false;
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        Network network = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            network = connectivityManager.getActiveNetwork();
            NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
            if (networkCapabilities != null) {
                int downSpeed = networkCapabilities.getLinkDownstreamBandwidthKbps();
                int upSpeed = networkCapabilities.getLinkUpstreamBandwidthKbps();

                // 判断网络速度
                if (downSpeed > 1000) {
                    // 网速较快
                } else {
                    // 网速较慢
                }
            }
        }



        if (networkInfo != null && networkInfo.isConnected()) {
            // 设备有网络连接
            isNet=true;
        } else {
            // 设备没有网络连接
            isNet=false;
        }
        return isNet;
    }
}
